﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Tools;
using Wp.DAL;

namespace Wp.BLL
{
    /// <summary>
    /// Summary description for Per_ActionsRoles
    /// </summary>
    public class TblCommentsManager : TblCommentsManagerBase
    {
        public TblCommentsManager()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public static TblCommentsManager CreateInstant()
        {
            return new TblCommentsManager();
        }
        /// <summary>
        /// Approved: new,approved,unapproved
        /// </summary>
        /// <param name="PostId"></param>
        /// <param name="ParentId"></param>
        /// <param name="Approved"></param>
        /// <returns></returns>
        public List<TblCommentsEntity> SelectByPost(int? PostId, int? ParentId, string Approved, int Top)
        {
            List<TblCommentsEntity> lsresult = new List<TblCommentsEntity>();
            List<SqlParameter> ls = new List<SqlParameter>();
            if (PostId.HasValue)
                ls.Add(new SqlParameter("@PostId", PostId.Value));
            if (ParentId.HasValue)
                ls.Add(new SqlParameter("@ParentId", ParentId.Value));
            if (Approved != "")
                ls.Add(new SqlParameter("@Approved", Approved));
            ls.Add(new SqlParameter("@Top", Top));
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.WpConnectString, CommandType.StoredProcedure, "wp_SelectTblComment", sqlparam);
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetTblCommentsEntity(dt.Rows[i]));
            return lsresult;
        }
        public int NumCommentOfPost(int PostId)
        {
            return SelectByPost(PostId, null, "approved",10000).Count;
        }
    }
}
